home *** CD-ROM | disk | FTP | other *** search
/ ETO Development Tools 4 / ETO Development Tools 4.iso / Tools - Objects / MacsBug / MacsBug 6.2.1 / dcmds / C Samples / Vol.c < prev    next >
Text File  |  1991-05-01  |  4KB  |  189 lines

  1. /*     vol.c
  2.     This is the VCB dcmd.
  3.  
  4.     Copyright © 1988 Apple Computer, Inc.  All rights reserved.
  5.  
  6.     Modification history:
  7.         29Nov88 sad        revised for new dcmd names.  display more info.
  8.          5Oct88 sad        written.
  9.  
  10.     The following MPW commands will build the dcmd and copy it to the
  11.     "Debugger Prefs" file in the System folder. The dcmd's name in
  12.     MacsBug will be the name of the file built by the Linker.
  13.     You must first copy dcmd.h, dcmdGlue.a.o and DRunTime.o from the
  14.     C Samples folder into this folder.
  15.  
  16.     C Put.c
  17.     C Vol.c
  18.     Link dcmdGlue.a.o Vol.c.o put.c.o DRuntime.o "{Libraries}"Interface.o -o Vol
  19.     BuildDcmd Vol 1002
  20.     Echo 'include "Vol";'    |    Rez -a -o "{systemFolder}Debugger Prefs"
  21. */
  22.  
  23. #include <Types.h>
  24. #include <Memory.h>
  25. #include <OSUtils.h>
  26. #include <Files.h>
  27.  
  28. #include "dcmd.h"
  29. #include "put.h"
  30.  
  31. #define VCBQHdr ((QHdrPtr)0x356)
  32.  
  33.  
  34. static void DrawHdr()
  35. {
  36. //                             1         2         3         4         5         6         7
  37. //                    1234567890123456789012345678901234567890123456789012345678901234567890123456789
  38.     dcmdDrawLine("\pvRef Vol        Flg dRef Drive FSID #Blk BlkSiz #Files  #Dirs Blsd Dir VCB at");
  39. }
  40.  
  41.  
  42. static void DrawVCB(VCB* vcbp)
  43. {
  44.     PutUHexWord(vcbp->vcbVRefNum);
  45.     PutSpace();
  46.     PutPStrTruncTo(vcbp->vcbVN,15);
  47.     PutSpace();
  48.     PutChar((vcbp->vcbFlags & 0x8000) ? 'D' : 'd');
  49.     PutChar((vcbp->vcbAtrb & 0x8000) ? 'S' : 's');
  50.     PutChar((vcbp->vcbAtrb & 0x4000) ? 'H' : 'h');
  51.     PutSpace();
  52.     PutUHexWord(vcbp->vcbDRefNum);
  53.     PutSpace();
  54.     PutSpace();
  55.     PutUHexWord(vcbp->vcbDrvNum);
  56.     PutSpace();
  57.     PutUHexWord(vcbp->vcbFSID);
  58.     PutSpace();
  59.     PutUHexWord(vcbp->vcbNmAlBlks);
  60.     PutSpace();
  61.     PutUHexZTo(vcbp->vcbAlBlkSiz,6,47);
  62.     PutSpace();
  63.     PutUHexZTo(vcbp->vcbFilCnt,6,54);
  64.     PutSpace();
  65.     PutUHexZTo(vcbp->vcbDirCnt,6,61);
  66.     PutSpace();
  67.     PutUHexZTo(vcbp->vcbFndrInfo[0],6,70);
  68.     PutSpace();
  69.     PutUHexZTo((unsigned long)vcbp,6,77);
  70.     PutLine();
  71. }
  72.  
  73.  
  74. static Boolean PrefixPStr(const Str255 astr, const Str255 bstr)
  75. // returns true if astr is equal to a prefix of bstr
  76. //    astr must not be longer than 31 characters
  77. {
  78.     char newstr[31];
  79.     int alen = *astr;
  80.     int blen = *bstr;
  81.     if (alen <= blen)
  82.         {
  83.         BlockMove(bstr+1,newstr+1,alen);
  84.         newstr[0] = alen;
  85.         return EqualString(astr,newstr,false,true);
  86.         }
  87.     else return false;    
  88. } // PrefixPStr
  89.  
  90. // EJECT
  91.  
  92. pascal void CommandEntry(dcmdBlock* paramPtr)
  93. {
  94.     switch (paramPtr->request)
  95.         {
  96.         case dcmdInit:
  97.             break;
  98.  
  99.         case dcmdHelp:
  100.             dcmdDrawLine("\pvol [vRefNum|drvNum|\"vol name\"]");
  101.             dcmdDrawLine("\p   Displays volume information for the given vrefnum, volume name or all mounted volumes.");
  102.             dcmdDrawLine("\p      Flags are D/d=Dirty, S/s=Software locked, H/h=Hardware locked.");
  103.             break;
  104.  
  105.         case dcmdDoIt:
  106.             {
  107.             Boolean doOneVCB = false;
  108.             long vref;
  109.             short c;
  110.             Boolean haveVolName = false;
  111.             Str255 volname;
  112.             VCB* vcbp;
  113.             int numvcbs = 0;
  114.             Boolean foundOne = false;
  115.  
  116.             dcmdSwapWorlds();
  117.  
  118.             dcmdDrawLine("\pDisplaying Volume Control Blocks");
  119.  
  120.           // get low-memory values after dcmdSwapWorlds()
  121.             vcbp = (VCB*)(VCBQHdr->qHead);
  122.  
  123.             c = dcmdPeekAtNextChar();
  124.             if (c == '"' || c == '\'')
  125.                 {
  126.                 haveVolName = true;
  127.                 (void)dcmdGetNextParameter(volname);
  128.                 }
  129.             else (void)dcmdGetNextExpression(&vref, &doOneVCB);
  130.  
  131.             if (doOneVCB) vref = (short)vref;
  132.  
  133.             while (vcbp)
  134.                 {
  135.                 if ((doOneVCB && (vcbp->vcbVRefNum == vref || vcbp->vcbDrvNum == vref)) ||
  136.                     (haveVolName && PrefixPStr(volname,vcbp->vcbVN)) ||
  137.                     (!doOneVCB && !haveVolName))
  138.                     {
  139.                     numvcbs++;
  140.                     if (!foundOne)
  141.                         {
  142.                         DrawHdr();
  143.                         foundOne = true;
  144.                         }
  145.                     DrawVCB(vcbp);
  146.                     }
  147.                 if (paramPtr->aborted) break;
  148.                 if (vcbp->qLink == 0)
  149.                     if (vcbp != (VCB*)(VCBQHdr->qTail))
  150.                         dcmdDrawLine("\pVCB queue does not end at VCBQHdr.qTail");
  151.                 vcbp = (VCB*)vcbp->qLink;
  152.                 }
  153.             if (!paramPtr->aborted)
  154.                 if (haveVolName || doOneVCB)
  155.                     {
  156.                     if (!foundOne)
  157.                         if (haveVolName)
  158.                             {
  159.                             PutPStr("\pno mounted volumes match \"");
  160.                             PutPStr(volname);
  161.                             PutChar('"');
  162.                             PutLine();
  163.                             }
  164.                         else
  165.                             {
  166.                             PutPStr("\pno mounted volumes match ");
  167.                             PutUHexWord(vref);
  168.                             PutLine();
  169.                             }
  170.                     }
  171.                 else
  172.                     {
  173.                     PutUDec(numvcbs);
  174.                     PutPStr("\p VCBs");
  175.                     PutLine();
  176.                     }
  177.  
  178.             dcmdSwapWorlds();
  179.             }
  180.             break;
  181.  
  182.         default:
  183.             PutPStr("\punknown request ");
  184.             PutUDec(paramPtr->request);
  185.             PutLine();
  186.             break;
  187.         }
  188. } // CommandEntry
  189.